package com.jesper.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jesper.model.Order;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OrderMapper extends BaseMapper<Order> {


//    @Insert(" insert into tb_order (order_id, payment, payment_type,\n" +
//            "        post_fee, status, create_time,\n" +
//            "        update_time, payment_time, consign_time,\n" +
//            "        end_time, close_time, shipping_name,\n" +
//            "        shipping_code, user_id, buyer_message,\n" +
//            "        buyer_nick, buyer_rate)\n" +
//            "        values (#{orderId,jdbcType=VARCHAR}, #{payment,jdbcType=VARCHAR}, #{paymentType,jdbcType=INTEGER},\n" +
//            "        #{postFee,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},\n" +
//            "        #{updateTime,jdbcType=TIMESTAMP}, #{paymentTime,jdbcType=TIMESTAMP}, #{consignTime,jdbcType=TIMESTAMP},\n" +
//            "        #{endTime,jdbcType=TIMESTAMP}, #{closeTime,jdbcType=TIMESTAMP}, #{shippingName,jdbcType=VARCHAR},\n" +
//            "        #{shippingCode,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT}, #{buyerMessage,jdbcType=VARCHAR},\n" +
//            "        #{buyerNick,jdbcType=VARCHAR}, #{buyerRate,jdbcType=INTEGER})")
//    int insert(Order record);


    @Select("select order_id, payment, payment_type, post_fee, status, create_time, update_time,\n" +
            "        payment_time, consign_time, end_time, close_time, shipping_name, shipping_code, user_id,\n" +
            "        buyer_message, buyer_nick, buyer_rate, refundStatus, refundReason, isRefund\n" +
            "        from tb_order where isRefund = 1")
    List<Order> listRefund(Order order);


    @Select("select count(*) from tb_order where date_format( create_time, '%Y-%m') = date_format(now(), '%Y-%m')")
    Integer selectCurOrderNum();

    @Select(" select count(*) from tb_order where period_diff(date_format(now(),'%Y%m'), date_format(create_time,'%Y%m')) = 1")
    Integer selectLastOrderNum();

    @Select("SELECT SUM(payment) FROM tb_order\n" +
            "        where status = 5 AND date_format(create_time, '%Y-%m') = date_format(now(), '%Y-%m')")
    Long selectCurPayment();

    @Select("SELECT SUM(payment) FROM tb_order\n" +
            "        where  status = 5 AND  period_diff(date_format(now(),'%Y%m'), date_format(create_time,'%Y%m')) = 1")
    Long selectLastPayment();

    @Insert("SELECT count(*) FROM tb_order\n" +
            "        where date_format(update_time, '%Y-%m') = date_format(now(), '%Y-%m')\n" +
            "        AND  refundStatus = 3")
    Integer selectCurRefundOrder();

    @Select("SELECT count(*) FROM tb_order\n" +
            "        where period_diff(date_format(now(),'%Y%m'), date_format(update_time,'%Y%m')) = 1\n" +
            "        AND  refundStatus = 3")
    Integer selectLastRefundOrder();


    @Select("SELECT sum(payment) FROM tb_order\n" +
            "        WHERE create_time BETWEEN  #{createTime, jdbcType=DATE} AND  date_add(#{createTime, jdbcType=DATE}, interval 1 day)")
    Integer selectDayOrderSum(Order order);
}